#include "jwsmtp/jwsmtp.h"

void sendMail(const char *msg)
{
	user u(string("admin"));

	string sendMailBox;
	string receiveMailBox;
	string mailTitle;
	string smtpServer;
	string pwd;

	string userName;
	size_t pos;

	u.get_send_mailbox(sendMailBox);
	u.get_receive_mailbox(receiveMailBox);
	u.get_email_title(mailTitle);
	u.get_smtp_server(smtpServer);
	u.get_send_mail_pwd(pwd);

	if(sendMailBox.empty() ||
		receiveMailBox.empty() ||
		mailTitle.empty() ||
		smtpServer.empty() ||
		pwd.empty())
		return;

	userName = sendMailBox;
	pos = userName.find(string("@"));
	userName = userName.erase(pos, userName.length());
//	cout << "user name is : " << userName << endl;
//	cout << "pwd : " << pwd << endl;
//	cout << "send box: " << sendMailBox << endl;
//	cout << "rev box : " << receiveMailBox << endl;
//	cout << "smtp " << smtpServer << endl;
//	cout << "msg: " << msg <<endl;

	cout << "\nPlease wait sending mail..." << endl;
	jwsmtp::mailer mail(
		receiveMailBox.c_str(),
		sendMailBox.c_str(),
		mailTitle.c_str(),
		msg,
		smtpServer.c_str(),
		jwsmtp::mailer::SMTP_PORT,
		false
		);
	mail.username(userName.c_str());
	mail.password(pwd.c_str());
	mail.authtype(jwsmtp::mailer::PLAIN);
	mail.operator()();

	cout << mail.response() << endl; 
}

